<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>pvinterp</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="pvcross.html" title="pvcross" />
    <link rel="next" href="pvoc.html" title="pvoc" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">pvinterp</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="pvcross.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="pvoc.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="pvinterp"></a>
      <div class="titlepage"></div>
      <a id="IndexPvinterp" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">pvinterp</span>
        </h2>
        <p>pvinterp — 
      Interpolates between the amplitudes and frequencies of two phase vocoder analysis files.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp137210336"></a>
        <h2>Description</h2>
        <p>
      <span class="emphasis"><em>pvinterp</em></span> interpolates between the amplitudes and frequencies, on a bin by bin basis, of two phase vocoder analysis files (one from a previously called <span class="emphasis"><em>pvbufread</em></span> unit and the other from within its own argument list), allowing for user defined transitions between analyzed sounds. It also allows for general scaling of the amplitudes and frequencies of each file separately before the interpolated values are calculated and sent to the resynthesis routines. The <span class="emphasis"><em>kfmod</em></span> argument in <span class="emphasis"><em>pvinterp</em></span> performs its frequency scaling on the frequency values after their derivation from the separate scaling and subsequent interpolation is performed so that this acts as an overall scaling value of the new frequency components.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp137213904"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>pvinterp</strong></span> ktimpnt, kfmod, ifile, kfreqscale1, kfreqscale2, \
      kampscale1, kampscale2, kfreqinterp, kampinterp</pre>
      </div>
      <div class="refsect1">
        <a id="idp137216208"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>ifile</em></span> -- the <span class="emphasis"><em>pvoc</em></span> number (n in pvoc.n) or the name in quotes of the analysis file made using pvanal. (See <a class="link" href="pvoc.html" title="pvoc"><em class="citetitle">pvoc</em></a>.)
    </p>
      </div>
      <div class="refsect1">
        <a id="idp137219328"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ktimpnt</em></span> -- the passage of time, in seconds, through this file. <span class="emphasis"><em>ktimpnt</em></span> must always be positive, but can move forwards or backwards in time, be stationary or discontinuous, as a pointer into the analysis file.
    </p>
        <p>
      <span class="emphasis"><em>kfmod</em></span> -- a control-rate transposition factor: a value of 1 incurs no transposition, 1.5 transposes up a perfect fifth, and .5 down an octave. 
    </p>
        <p>
      <span class="emphasis"><em>kfreqscale1</em></span>, <span class="emphasis"><em>kfreqscale2</em></span>, <span class="emphasis"><em>kampscale1</em></span>, <span class="emphasis"><em>kampscale2</em></span> -- used in <span class="emphasis"><em>pvinterp</em></span> to scale the frequencies and amplitudes stored in each frame of the phase vocoder analysis file. <span class="emphasis"><em>kfreqscale1</em></span> and <span class="emphasis"><em>kampscale1</em></span> scale the frequencies and amplitudes of the data from the file read by the previously called <a class="link" href="pvbufread.html" title="pvbufread"><em class="citetitle">pvbufread</em></a> (this data is passed internally to the <span class="emphasis"><em>pvinterp</em></span> unit). <span class="emphasis"><em>kfreqscale2</em></span> and <span class="emphasis"><em>kampscale2</em></span> scale the frequencies and amplitudes of the file named by <span class="emphasis"><em>ifile</em></span> in the <span class="emphasis"><em>pvinterp</em></span> argument list and read within the <span class="emphasis"><em>pvinterp</em></span> unit. 
    </p>
        <p>
      By using these arguments, it is possible to adjust these values before applying the interpolation. For example, if file1 is much louder than file2, it might be desirable to scale down the amplitudes of file1 or scale up those of file2 before interpolating. Likewise one can adjust the frequencies of each to bring them more in accord with one another (or just the opposite, of course!) before the interpolation is performed.
    </p>
        <p>
      <span class="emphasis"><em>kfreqinterp</em></span>, <span class="emphasis"><em>kampinterp</em></span> -- used in <span class="emphasis"><em>pvinterp</em></span>, determine the interpolation distance between the values of one phase vocoder file and the values of a second file. When the value of <span class="emphasis"><em>kfreqinterp</em></span> is 1, the frequency values will be entirely those from the first file (read by the <span class="emphasis"><em>pvbufread</em></span>), post scaling by the <span class="emphasis"><em>kfreqscale1</em></span> argument. When the value of <span class="emphasis"><em>kfreqinterp</em></span> is 0 the frequency values will be those of the second file (read by the <span class="emphasis"><em>pvinterp</em></span> unit itself), post scaling by <span class="emphasis"><em>kfreqscale2</em></span>. When <span class="emphasis"><em>kfreqinterp</em></span> is between 0 and 1 the frequency values will be calculated, on a bin, by bin basis, as the percentage between each pair of frequencies (in other words, <span class="emphasis"><em>kfreqinterp</em></span>=0.5 will cause the frequencies values to be half way between the values in the set of data from the first file and the set of data from the second file).
    </p>
        <p>
      <span class="emphasis"><em>kampinterp</em></span> works in the same way upon the amplitudes of the two files. Since these are k-rate arguments, the percentages can change over time making it possible to create many kinds of transitions between sounds.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp137237488"></a>
        <h2>Examples</h2>
        <p>
      The example below shows an example using <span class="emphasis"><em>pvbufread</em></span> with <span class="emphasis"><em>pvinterp</em></span> to interpolate between the sound of an oboe and the sound of a clarinet. The value of <span class="emphasis"><em>kinterp</em></span> returned by a <span class="emphasis"><em>linseg</em></span> is used to determine the timing of the transitions between the two sounds. The interpolation of frequencies and amplitudes are controlled by the same factor in this example, but for other effects it might be interesting to not have them synchronized in this way. In this example the sound will begin as a clarinet, transform into the oboe and then return again to the clarinet sound. The value of <span class="emphasis"><em>kfreqscale2</em></span> is 1.065 because the oboe in this case is a semitone higher in pitch than the clarinet and this brings them approximately to the same pitch. The value of <span class="emphasis"><em>kampscale2</em></span> is 0.75 because the analyzed clarinet was somewhat louder than the analyzed oboe. The setting of these two parameters make the transition quite smooth in this case, but such adjustments are by no means necessary or even advocated.
    </p>
        <p>
      </p>
        <div class="informalexample">
          <pre class="programlisting">
ktime1  <span class="opc">line</span>      0, p3, 3.5 <span class="comment">; used as index in the "oboe.pvoc" file</span>
ktime2  <span class="opc">line</span>      0, p3, 4.5 <span class="comment">; used as index in the  "clar.pvoc" file</span>
kinterp <span class="opc">linseg</span>    1, p3<span class="op">*</span>0.15, 1, p3<span class="op">*</span>0.35, 0, p3<span class="op">*</span>0.25, 0, p3<span class="op">*</span>0.15, 1, p3<span class="op">*</span>0.1, 1
        <span class="opc">pvbufread</span> ktime1, "oboe.pvoc"
apv     <span class="opc">pvinterp</span>  ktime2,1,"clar.pvoc", 1, 1.065, 1, 0.75, 1<span class="op">-</span>kinterp, 1<span class="op">-</span>kinterp</pre>
        </div>
        <p>
    </p>
        <p>
      Here is a complete example of the pvinterp opcode. It uses the file <a class="ulink" href="examples/pvinterp.csd" target="_top"><em class="citetitle">pvinterp.csd</em></a>
      </p>
        <div class="example">
          <a id="idp137254400"></a>
          <p class="title">
            <strong>Example 666. Example of the pvinterp opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac   <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o pvinterp.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100 
<span class="ohdr">ksmps</span> <span class="op">=</span> 32 
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1 
<span class="ohdr">nchnls</span> <span class="op">=</span> 2

<span class="oblock">instr</span> 1
<span class="comment">; analyze "fox.wav" and "flute.aiff" with PVANAL first</span>
ktime1 <span class="opc">line</span> 0, p3, 2.8		 <span class="comment">; used as index in the "fox.pvx" file</span>
ktime2 <span class="opc">line</span> 0, p3, 3		 <span class="comment">; used as index in the "flute.pvx" file</span>
kinterp <span class="opc">line</span> 1, p3, 0
	<span class="opc">pvbufread</span> ktime1, "fox.pvx"
asig	<span class="opc">pvinterp</span> ktime2,1,"flute.pvx",.9, 3, .6, 1, kinterp,1<span class="op">-</span>kinterp
        <span class="opc">outs</span> asig, asig

<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 3
<span class="stamnt">i</span> 1 + 10

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp137258688"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="pvbufread.html" title="pvbufread"><em class="citetitle">pvbufread</em></a>,
      <a class="link" href="pvcross.html" title="pvcross"><em class="citetitle">pvcross</em></a>,
      <a class="link" href="pvread.html" title="pvread"><em class="citetitle">pvread</em></a>,
      <a class="link" href="tableseg.html" title="tableseg"><em class="citetitle">tableseg</em></a>,
      <a class="link" href="tablexseg.html" title="tablexseg"><em class="citetitle">tablexseg</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp137264576"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Richard Karpen</td>
          </tr>
          <tr>
            <td>Seattle, Wash</td>
          </tr>
          <tr>
            <td>1997</td>
          </tr>
        </table>
        <p>
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="pvcross.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="pvoc.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">pvcross </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> pvoc</td>
        </tr>
      </table>
    </div>
  </body>
</html>
